;;;Custom Dialog routine written for Dennis Facia to label landscape plantings.
;;;Requirements:
;;;      MKLAYR.LSP, MLT.LSP, UUTILS.LSP, GETSTYLE.LSP
;;;      (preexisting routines by H.C. Francis)
;;;
;;;      Author:  Henry C. Francis
;;;               425 N. Ashe Street
;;;               Southern Pines, NC 28387
;;;
;;;	http://www.paracadd.com
;;;      All rights reserved
;;;
;;;     Created:  3/13/97
;;;
(defun c:lslbl ( / )
  (setq rapn "PLANTING_NOTE")
  (regapp rapn)
  (load"mlt")
  (load"lstbl")
  (setq num (load_dialog "lslbl"))
  (new_dialog "lslbl" num)
  (setq matl_list nil)
  (action_tile "data_opt" "(setq dopt (get_tile\"data_opt\"))(matllst)")
  (action_tile "matl_opt" "(setq mopt (get_tile\"matl_opt\"))")
  (action_tile
    "Numb_slide"
    "(setq q_reqd (get_tile\"Numb_slide\"))(set_tile\"Numb_items\"q_reqd)(set_reqd)"
  )
  (action_tile
    "Numb_items"
    "(setq q_reqd (get_tile\"Numb_items\"))(set_tile\"Numb_slide\"q_reqd)(set_reqd)"
  )
  (action_tile "accept" "(set_note)(setq do_note T)(done_dialog)")
  (action_tile "cancel" "(setq do_note nil typ_t1 nil)")
  (action_tile "help" "(acad_helpdlg \"lslbl.hlp\" \"LSN\")")
  (if dopt nil (setq dopt "0"))
  (if mopt nil (setq mopt "0"))
  (mode_tile "matl_opt" 2)
  (set_tile "matl_opt" mopt)
  (datalst)
  (matllst)
  (set_reqd)
  (start_dialog)
  (if do_note
    (progn
      (c:mlt)
      (setq txent (entget(entlast)))
      (setq txent (append txent (list xelist)))
      (entmod txent)
      (setq xelist nil)
    )
    (setq xelist nil)
  )
  (princ)
)
;;;********************************************************************
(defun datalst (/ data_list)
  (setq opt_file (findfile "lsdopt.lsd"))
  (if opt_file
    (progn
      (setq df1 (open opt_file "r"))
      (while
        (setq opt_line (read-line df1))
        (if data_list
          (setq data_list (append data_list (list opt_line)))
          (setq data_list (list opt_line))
        )
      )
      (close df1)
    )
  )
  (setq data_list (acad_strlsort data_list))
  (setq opt_list data_list)
  (start_list "data_opt")
  (mapcar 'add_list data_list )
  (end_list)
  (princ)
)
;;;********************************************************************
(defun matllst ()
  (setq matl_list nil)
  (setq matl_file (findfile (strcat (substr (nth (atoi dopt) opt_list) 1 8)".mat")))
  (if matl_file
    (progn
      (setq df1 (open matl_file "r"))
      (while
        (setq matl_line (read-line df1))
        (if matl_list
          (setq matl_list (append matl_list (list matl_line)))
          (setq matl_list (list matl_line))
        )
      )
      (close df1)
    )
    (if (and dopt opt_list)
      (setq matl_list (list (strcat (nth (atoi dopt) opt_list)" Material File Not Found!")))
      (setq matl_list (list "Material File Not Found!"))
    )
  )
  (setq matl_list (acad_strlsort matl_list))
  (start_list "matl_opt")
  (mapcar 'add_list matl_list )
  (end_list)
  (princ)
)
;;;********************************************************************
(defun set_reqd ()
  (if q_reqd nil (setq q_reqd "1"))
  (set_tile "Numb_items" q_reqd)
  (set_tile "Numb_slide" q_reqd)
)
;;;********************************************************************
(defun set_note ( / sndx1 sndx2)
  (setq tindx 1
        count 1
        rcount 0)
  (setq typ_t1 (strcat "(" q_reqd ") " (nth (atoi mopt) matl_list)))
  (setq slen (strlen typ_t1))
  (while (<= tindx slen)
    (if (eq "\t" (substr typ_t1 tindx 1))
      (progn
        (set (read(strcat "cidx" (itoa count)))tindx)
        (setq count (1+ count)
	      rcount (1- count)
              tindx (1+ tindx))
      )
      (setq tindx (1+ tindx))
    )
  )
  (while (> rcount 0)
    (setq sndx1 (eval(read(strcat "cidx" (itoa rcount)))))
    (if xelist
      (setq xelist
        (append
	  (if sndx2
            (list(cons 1000 (substr typ_t1 (1+ sndx1) (- sndx2 (1+ sndx1)))))
            (list(cons 1000 (substr typ_t1 (1+ sndx1))))
	  )
	  xelist
	)
      )
      (setq xelist
        (if sndx2
          (list(cons 1000 (substr typ_t1 (1+ sndx1) (- sndx2 (1+ sndx1)))))
          (list(cons 1000 (substr typ_t1 (1+ sndx1))))
	)
      )
    )
    (setq rcount (1- rcount))
    (setq sndx2 sndx1
          sndx1 1)
  )
  (if xelist
    (setq xelist
      (list -3 (append (list rapn) (list(cons 1002 "{")) xelist (list(cons 1002 "}"))))
    )
  )
  (setq typ_t1 (substr typ_t1 1 (1- cidx1)))
  (setq sndx2 nil
        cidx1 nil
        cidx2 nil
	cidx3 nil)
)
;;;********************************************************************
(defun *error* ( msg /)
  (if (/= msg "Function cancelled")
    (if (= msg "quit / exit abort")
      (progn
        (term_dialog)
        (princ)
      )
      (progn
        (term_dialog)
        (princ (strcat "\nError: " msg))
        (princ)
      )
    )
    (progn
      (term_dialog)
      (princ)
    )
  )
)
(princ)
;;;********************************************************************
(defun c:lsn ()
(setq do_note t)
(while do_note
  (c:lslbl)
)
(setq thts nil)
)